#include "tcl_mstar_atv_tv.h"

TCL_MSTAR_ATV_TV::TCL_MSTAR_ATV_TV()
{
}

TCL_MSTAR_ATV_TV::~TCL_MSTAR_ATV_TV()
{

}
int TCL_MSTAR_ATV_TV::Read_Data(QDataStream &in)
{
  in>>ui2_ch_val
    >>ps_name
    >>ui2_class
    >>ui4_freq
    >>ui2_isfav
    >>ui2_isskip;

  return 1;
}

int TCL_MSTAR_ATV_TV::Write_Data(QDataStream &out)
{
  out<<ui2_ch_val
     <<ps_name
     <<ui2_class
     <<ui4_freq
     <<ui2_isfav
    <<ui2_isskip;

  return 1;
}

void TCL_MSTAR_ATV_TV::Set_Data(int order,QVariant value)
{
    bool flag=false;
    bool *ok=&flag;
     switch(order)
     {
     case 0:
     {
        ui2_ch_val=(ushort)value.toUInt(ok);
        STRING_TRAN_ERROR_0;
        break;
     }
     case 1:
     {
        ps_name=value.toString();
        break;
     }
     case 3:
     {
         ui4_freq=value.toUInt(ok);
        STRING_TRAN_ERROR_0;
         break;
     }
     case 4:
     {
        ui2_isfav=(ushort)value.toUInt(ok);
        STRING_TRAN_ERROR_0;
        break;
     }
     case 5:
     {
        ui2_isskip=(ushort)value.toUInt(ok);
         STRING_TRAN_ERROR_0;
        break;
     }
     case 2:
     {
        ui2_class=(ushort)value.toUInt(ok);
        STRING_TRAN_ERROR_0;
        break;
     }
     default:
         Q_ASSERT(order>=0&&order<NUM_TV_ITEM);
     }
}

void TCL_MSTAR_ATV_TV::Get_Data(QString &tv_class,QString &tv_freq,QString &tv_fav,QString &tv_skip,QString &tv_chval,QString &name)
{
    tv_chval.setNum(ui2_ch_val);
    name=ps_name;
    tv_class.setNum(ui2_class);
    tv_fav.setNum(ui2_isfav);
    tv_skip.setNum(ui2_isskip);
    tv_freq.setNum(ui4_freq);

}

void TCL_MSTAR_ATV_TV::Get_Data(QList<QString>* atv_data)
{
    QString tmp;
    Q_CHECK_PTR(atv_data);
    tmp.setNum(ui2_ch_val);
    atv_data->append(tmp);
    atv_data->append(ps_name);
    if(ui2_class==0)
        tmp="air";
    else
        tmp="cable";
    atv_data->append(tmp);
    tmp.setNum(ui4_freq);
    atv_data->append(tmp);
    tmp.setNum(ui2_isfav);
    atv_data->append(tmp);
    tmp.setNum(ui2_isskip);
    atv_data->append(tmp);

}
int TCL_MSTAR_ATV_TV::Set_Data(QString &tv_class,QString &tv_freq,QString &tv_fav,QString &tv_skip,QString &tv_chval,QString &name)
{
    bool flag=false;
    bool *ok=&flag;
    ui2_ch_val=tv_chval.toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ps_name=name;
    ui2_class=tv_class.toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ui4_freq=tv_freq.toUInt(ok);
    STRING_TRAN_ERROR_1(-1);
    ui2_isfav=tv_fav.toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ui2_isskip=tv_skip.toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ps_name=name;
}
void TCL_MSTAR_ATV_TV::Set_Data(QList<QString> &ch_data)
{
    bool flag=false;
    bool *ok=&flag;
    ui2_ch_val=ch_data.at(0).toUShort(ok);
    STRING_TRAN_ERROR_0;
    ps_name=ch_data.at(1);
    STRING_TRAN_ERROR_0;
    ui2_class=ch_data.at(2).toUShort(ok);
    STRING_TRAN_ERROR_0;
    ui4_freq=ch_data.at(3).toUInt(ok);
    STRING_TRAN_ERROR_0;
    ui2_isfav=ch_data.at(4).toUShort(ok);
    STRING_TRAN_ERROR_0;
    ui2_isskip=ch_data.at(5).toUShort(ok);
    STRING_TRAN_ERROR_0;

}

int TCL_MSTAR_ATV_TV::Count_Item()
{
    return NUM_TV_ITEM;
}


QString TCL_MSTAR_ATV_TV::Get_Item(int i)
{
    QString tmp;
    switch(i)
    {
    case 0:
        tmp.setNum(ui2_ch_val);
        break;
    case 1:
        tmp=ps_name;
        break;
    case 2:
        tmp.setNum(ui2_class);
        break;
    case 3:
        tmp.setNum(ui4_freq);
        break;
    case 4:
        tmp.setNum(ui2_isfav);
        break;
    case 5:
        tmp.setNum(ui2_isskip);
        break;
      default:
        Q_ASSERT(0>=i&&i<NUM_TV_ITEM);
    }
    return tmp;
}
